import QRequest from '@/service/index';
import { generateNameToLevel } from '@/config/constant';

import {
    supplierParams,
    supplierResponse,
    MaterialParams,
    MaterialResponse,
    AddSupplierData
} from './model/type';

/**
 * @:获取供应商列表
 * @param {supplierParams} params
 * @return {*}
 */
export const doGetSupplierList = (params: supplierParams) => {
    return QRequest.get<supplierResponse>(`/supplier/selectAll`, { params });
};

/**
 * @: 删除供应商
 * @param {object} params
 * @return {*}
 */
export const doDelSupplier = (params: { supplierIds?: string; materialId?: string }) => {
    return QRequest.delete(`/supplier/delete`, {
        params,
        headers: {
            hideLoading: 1
        }
    });
};

/**
 * @: 新增供应商
 * @param {AddSupplierData} data
 * @return {*}
 */
export const doAddSupplier = (data: AddSupplierData) => {
    return QRequest.post(`/supplier/save`, data, {
        headers: {
            hideLoading: 1
        }
    });
};

/**
 * @: 编辑供应商
 * @param {AddSupplierData} data
 * @return {*}
 */
export const doUpdateSupplier = (data: AddSupplierData) => {
    return QRequest.put(`/supplier/update`, data, {
        headers: {
            hideLoading: 1
        }
    });
};

/**
 * @: 获取物料详情
 * @param {string} id
 * @return {*}
 */
export const doGetSupplierDetail = (id: string) => {
    return QRequest.get<AddSupplierData>(`/supplier/selectById`, {
        params: { id },
        headers: {
            hideLoading: 1
        }
    });
};

/**
 * @: 获取物料列表
 * @param {MaterialParams} params
 * @return {*}
 */
export const doGetMaterialList = (params: MaterialParams) => {
    return QRequest.get<MaterialResponse>(`/material/selectAll`, {
        params,
        headers: {
            loadingTarget: `#${generateNameToLevel('1')}`
        }
    });
};
